import com.alibaba.excel.EasyExcel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hjc-YYDS
 * @date 2024/3/5 14:56
 */
@Slf4j
public class MyTest03 {
    //使用模版export-template.xlsx
    @SneakyThrows
    @Test
    public void testFileWriteWithHeader02() {
        InputStream stream = MyTest03.class.getClassLoader().getResourceAsStream("export-template.xlsx");

        Map<String, Object> map1 = new HashMap<>();
        map1.put("role", "白起");
        map1.put("gender", "男");
        map1.put("home", "咸阳");
        map1.put("date", "1826-01-01");

        Map<String, Object> map2 = new HashMap<>();
        map2.put("role", "王翦");
        map2.put("gender", "男");
        map2.put("home", "咸阳");
        map2.put("date", "1826-01-01");

        Map<String, Object> map3 = new HashMap<>();
        map3.put("role", "赵奢");
        map3.put("gender", "男");
        map3.put("home", "邯郸");
        map3.put("date", "1826-01-01");

        Map<String, Object> map4 = new HashMap<>();
        map4.put("role", "廉颇");
        map4.put("gender", "男");
        map4.put("home", "邯郸");
        map4.put("date", "1826-01-01");

        List<Map<String, Object>> mapList = Arrays.asList(map1, map2, map3, map4);

        EasyExcel.write("D:\\D00_recently\\test5.xlsx")
                .withTemplate(stream).sheet().doFill(mapList);

    }

    @SneakyThrows
    @Test
    public void testFileWriteWithHeader03() {
        InputStream stream = MyTest03.class.getClassLoader().getResourceAsStream("export-template.xlsx");

        Role role1 = new Role("白起", "男", "咸阳", "1826-01-01");
        Role role2 = new Role("王翦", "男", "咸阳", "1826-01-01");
        Role role3 = new Role("赵奢", "男", "邯郸", "1826-01-01");
        Role role4 = new Role("廉颇", "男", "邯郸", "1826-01-01");

        List<Role> roleList = Arrays.asList(role1, role2, role3, role4);

        EasyExcel.write("D:\\D00_recently\\test6.xlsx")
                .withTemplate(stream).sheet().doFill(roleList);
    }
}
